/*
 * hal_motor_pwm_controller.h
 *
 *  Created on: 2025 Apr 9
 *      Author: SFLY
 */

#ifndef XTFOCLIB_HAL_DRIVERS_HAL_MOTOR_PWM_CONTROLLER_H_
#define XTFOCLIB_HAL_DRIVERS_HAL_MOTOR_PWM_CONTROLLER_H_
#include "bsp_board_config.h"
#include "mod_math.h"
typedef struct{
    float VaReal;
    float VbReal;
    float MaxDutyCnt;
    uint16_t PeakCnt;
    uint16_t u8Sector;
    uint16_t u8OvFlag;
    uint16_t u16T0;
    uint16_t u16T1;
    uint16_t u16T2;
}xt_hal_motor_svpwm_caculator_t;//SVPWM调制器

typedef struct{
    xt_hal_motor_svpwm_caculator_t svpwm_caculator;
    uint16_t u16Uon;
    uint16_t u16Uoff;
    uint16_t u16Von;
    uint16_t u16Voff;
    uint16_t u16Won;
    uint16_t u16Woff;
    uint32_t  ErrorFlag;//电机控制器错误标识
    void (*svpwm_caculate)(float,float,float,xt_hal_motor_svpwm_caculator_t*);
    void (*motor_pwm_caculate)(xt_hal_motor_svpwm_caculator_t*,void*);
    void (*motor_pwm_enable)(int);
    void (*motor_pwm_set)(uint32_t,uint32_t,uint32_t);
    void (*motor_pwm_reset)(void*);
}xt_hal_motor_pwm_controller_t;//电机PWM控制器

void Hal_MotorPwm_Controller_Init(xt_hal_motor_pwm_controller_t* pwm_controller);
uint32_t Hal_SVPWM_Caculator_Init(uint16_t PeakCnt, float MaxDuty,void* svpwm_ptr);
void Hal_SVPWM_Caculate(float Va, float Vb, float Vbus,xt_hal_motor_svpwm_caculator_t* spvmw_ptr);
void Hal_MotorPwm_Caculate(xt_hal_motor_svpwm_caculator_t* spvmw_ptr,void* pwm_ptr);
void Hal_MotorPwm_Enable(int enFlag);
void Hal_MotorPwm_Set(uint32_t DutyU,uint32_t DutyV,uint32_t DutyW);
void Hal_MotorPwm_Reset(void* pwm_ptr);
#endif /* XTFOCLIB_HAL_DRIVERS_HAL_MOTOR_PWM_CONTROLLER_H_ */
